<!-- 批量提交 -->
<template>
	<view class="submitView">
		<view class="chooses">
			<image class="logo" src="../../static/tab5/date.png"></image>
			<view class="inputLine">
				<view class="inputData"><lyzml-datepicker ref="lyzmlDatePicker" :config="datePickerConfig" @onDateChange="onBirthDayChange1"></lyzml-datepicker></view>
				<text class="single">到</text>
				<image class="logo" src="../../static/tab5/date.png"></image>
				<view class="inputData"><lyzml-datepicker ref="lyzmlDatePicker" :config="datePickerConfig" @onDateChange="onBirthDayChange"></lyzml-datepicker></view>
			</view>
		</view>
		<view class="moneycount">
			<text>总金额</text>
			<text style="margin-left:10upx;color:red;">{{ totalList }}</text>
			<view class="record">
				<text style="color:#1c88ca;">查看记录详情</text>
				<image class="logos" src="../../static/tab5/pull.png" @click="isShow = !isShow" v-if="isShow"></image>
				<image class="logos" src="../../static/tab5/recover.png" @click="isShow = !isShow" v-else></image>
			</view>
		</view>

		<view class="appliciation" v-for="(item, index) in moneymanagerList" :key="index" v-if="isShow">
			<view class="methods">
				<text class="method">{{ item.details }}</text>
				<text style="position: absolute;right: 40upx;">{{ item.money }}</text>
			</view>
			<view class="date">{{ item.createTime }}</view>
		</view>
		<view class="input-view"><input type="text" placeholder="备注" name="remark" v-model="remark" /></view>
		<!-- <text class="loadMore">{{ contentText }}</text> -->
		<view class="button-view"><button type="primary" hover-class="hover" formType="submit" @click="submit">提交</button></view>
	</view>
</template>

<script>
import lyzmldatepicker from '../../components/lyzml-datepicker/lyzml-datepicker.vue';
export default {
	components: {
		lyzmldatepicker
	},
	computed: {
		datePickerConfig: function() {
			let retObj = {
				yearsBefore: 15,
				yearsAfter: 5,
				initType: 'ymd',
				initDate: ''
			};
			return retObj;
		}
	},
	data() {
		return {
			refreshing: false,
			fetchPageNum: 1,
			pageSize: 10,
			pullFlag: true,
			contentText: '上拉显示更多',
			totalList:0,
			isShow: false,
			moneymanagerList: [],
			remark:'',
			idList:[],
			fundRecordIds:''
		};
	},
	onLoad() {
		this.startTime = this.start;
		this.endTime = this.end;
		
	},
	onShow() {
		this.fetchPageNum = 1;
		this.pullFlag = true;
		this.refreshing = false;
		console.log('请求token', uni.getStorageSync('token'));
		this.getlists();
	},
	onReachBottom() {
		console.log('滑动到页面底部');
		this.contentText = '加载中...';
		if(this.pullFlag){
			this.fetchPageNum += 1;
			this.pulllists();
		}else{
			this.contentText = '暂无更多数据';
		}
		
		
	},
	onPullDownRefresh() {
		console.log('下拉刷新');
		// this.pullData();
		uni.startPullDownRefresh({
			//API开始下拉刷新操作
			success: res => {
				console.log('shuacin', this.fetchPageNum);
				this.refreshing = true;
				this.getlists(); //下拉刷新重新获取数据
				uni.stopPullDownRefresh(); //API停止下拉刷
				
			}
		});
	},
	methods: {
		onBirthDayChange1(e) {
			this.startTime = e.value;
			console.log('开始时间',this.startTime);
			this.getlists();
		},
		onBirthDayChange(e) {
			this.endTime= e.value;
			console.log('结束时间',this.endTime);
			this.getlists();
		},
		// 分页数据
		pulllists(){
			uni.request({
					url: this.$serverUrl + '/app/hospital/fundSubmitRecord/findFundRecordByTime', //仅为示例，并非真实接口地址。
					data: {
						'startTime':this.startTime,
						'endTime':this.endTime
					},
					method: 'POST',
					header: {
						'token': uni.getStorageSync('token'),
						'content-type': 'application/json',
						'content-type': 'application/x-www-form-urlencoded'
					},
					success:(res)=> {
						if (res.data.code == 0) {
								console.log("findSentimentManagerList == "+JSON.stringify(res));
								if (this.refreshing) {
									uni.showToast({
										title: '已经最新',
										icon: 'none'
									});
									this.refreshing = false;
									uni.stopPullDownRefresh();
									return;
								}
								let lists = [];
								let data = res.data.data;
								for (let i = 0; i < data.length; i++) {
									lists.push(data[i]);
								}
								if (lists.length < this.pageSize) {
									this.pullFlag = false;
									
								}
								console.log('得到lists', lists);
								
									
									this.moneymanagerList =this.moneymanagerList.concat(lists);
								
									console.log(this.moneymanagerList);
								
							}
							try {
								uni.setStorageSync('data', JSON.stringify(res.data.data));
							} catch (e) {}
						}
					
				});
			},
		// 获取数据
		getlists(){
			uni.request({
					url: this.$serverUrl + '/app/hospital/fundSubmitRecord/findFundRecordByTime', //仅为示例，并非真实接口地址。
					data: {
						'startTime':this.startTime,
						'endTime':this.endTime
					},
					method: 'POST',
					header: {
						'token': uni.getStorageSync('token'),
						'content-type': 'application/json',
						'content-type': 'application/x-www-form-urlencoded'
					},
					success:(res)=> {
						
						
						var list=res.data.data;
						// this.data.name=list.name
						
						
						var idlist=[];
						if (res.data.code == 0) {
							console.log(res.data);
							this.totalList = res.data.data.totalMoney;
							this.moneymanagerList = res.data.data.fundRecordList;
							for(var i=0;i<this.moneymanagerList.length;i++)
							{
								idlist.push(this.moneymanagerList[i].id)
							}
							console.log(idlist);
							this.fundRecordIds=idlist.join(',');
							console.log(this.fundRecordIds);
							uni.getStorageSync('token', res.data.token);
						} else {
							uni.showToast({
								title: res.data.msg,
								duration: 2000
							});
						}
					}
				});
			},
		
		setInitDate() {
			this.$refs.lyzmlDatePicker.initDate('2019-10-01');
		},
		// 批量提交
		submit(e) {
			uni.request({
				
				url:this.$serverUrl + '/app/hospital/fundSubmitRecord/submitFundRecord',
				data: {
					'fundRecordIdsStr':this.fundRecordIds,
					 totalMoney: this.totalList,
					'remark': this.remark,
					'startTime':this.startTime,
					'endTime':this.endTime
				},
				method: 'POST',
				header: {
					token: uni.getStorageSync('token'),
					'content-type': 'application/json',
					'content-type': 'application/x-www-form-urlencoded'
				},
				success: (res)=> {
					console.log(this.fundRecordIds);
					console.log(this.totalList);
					console.log( this.remark);
					console.log( this.startTime);
					console.log(this.endTime);
					if (res.data.code == 0) {
						uni.getStorageSync('token', res.data.token);
						uni.switchTab({
							url:'./manage'
						})
					}
					 else {
						uni.showToast({
							title: res.data.msg,
							duration: 2000
						});
					}
				}
			});
		}
	}
};
</script>

<style>
.submitView {
	flex-direction: column;
}

.single {
	margin-left: 40upx;
}

.chooses {
	margin-top: 50upx;
	height: 100upx;
	/* margin: 40upx; */
}
.moneycount {
	margin: 40upx;
	/* width: 10upx; */
}
.count {
	color: #ff0000;
	margin-left: 30upx;
}
.record {
	position: absolute;
	right: 40upx;
	/* margin-right:1upx; */
	color: #007aff;
}
/* .logo {
	margin-left: 50upx;
	margin-top: 5upx;
	height: 30upx;
	width: 30upx;
} */
.logo {
	margin-left: 40upx;
	margin-right: 10upx;
	height: 30upx;
	width: 30upx;
	margin-top: 5upx;
}
.logos {
	margin-left: 10upx;
	height: 30upx;
	width: 30upx;
	margin-top: 7upx;
}
.input-view {
	display: flex;
	border-bottom-style: solid;
	border-bottom-width: 1upx;
	border-bottom-color: #f0eff2;
	background-color: #fff;
	/* width: 600upx;*/
	width: auto;
	margin: 30upx;
	/* margin-right: 60upx; */
	padding: 30upx;
}
.label-view {
	width: 150upx;
	height: 60upx;
	align-items: center;
	margin-right: 30upx;
}
.appliciation {
	margin-left: 40upx;
	margin-bottom: 20upx;
	margin-right: 40upx;
	flex-direction: column;
	height: 200upx;
	border-top-style: solid;
	border-top-width: 2upx;
	border-top-color: #f0eff2;
	/* padding-right: 1upx; */
}

.methods {
	margin-top: 40upx;
	flex-direction: row;
	text-align: center;
}

.method {
	height: 70%;
	width: 70%;
	flex-direction: row;
	align-items: center;
	text-align: left;
}
.money {
	/* float: right; */
	flex-direction: row;
	align-items: center;
	text-align: right;
}
.date {
	margin-top: 40upx;
}

.button-view {
	position: fixed;
	width: 750upx;
	/* margin-top: 50upx; */
	/* margin-bottom: 50upx; */
	/* padding: 0 20upx; */
	box-sizing: border-box;
	flex-direction: column;
	bottom: 0upx;
}

button {
	margin-bottom: 10upx;
	width: 710upx;
	height: 80upx;
	line-height: 80upx;
	text-align: center;
	font-size: 38upx;
	background-color: #0079c3;
	border-radius: 150upx;
}

button.publish {
	border-radius: 150upx;
}
page,
view {
	display: flex;
}

page {
	display: flex;
	min-height: 100%;
	background-color: #ffffff;
}

template {
	display: flex;
	flex: 1;
}
</style>
